package com.xdh.zzqh.ui.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import android.widget.TextView
import com.xdh.zzqh.R

//抽水加热控制
class LabelSpinner(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) {

    private val sp: CustomSpinner
    private var items = emptyList<String>()

    init {
        val view = LayoutInflater.from(context).inflate(R.layout.view_key_spinner, this)
        val tv = view.findViewById<TextView>(R.id.id_ksp_tv)
        sp = view.findViewById(R.id.id_ksp_sp)

        val attr = context.obtainStyledAttributes(attrs, R.styleable.LabelSpinner)
        val key = attr.getString(R.styleable.LabelSpinner_lsp_key)
        items = attr.getTextArray(R.styleable.LabelSpinner_items).map { it.toString() }
        attr.recycle()

        tv.text = key

        setItems(items, key!!)
    }

    fun setItems(items: List<String>, title: String) {
        sp.setItems(items, title)
    }

    fun setSelectIndex(index: Int) {
        sp.setSelectIndex(index)
    }

    fun setItems(items: List<String>) {
        sp.setItems(items)
    }

    fun selectText(): String {
        return sp.selectText()
    }

    fun selectIndex() = sp.selectIndex()

    fun setSelectFunc(f: (String, Int) -> Unit) {
        sp.selectFunc = f
    }
}




